package com.app.micaihu.view.home.exclusive.adapter.provider

import android.app.Activity
import android.content.Intent
import android.widget.FrameLayout
import android.widget.ImageView
import com.app.micaihu.R
import com.app.micaihu.bean.news.NewsEntity
import com.app.micaihu.configure.Config
import com.app.micaihu.configure.UmEventId
import com.app.micaihu.utils.InteractiveUtils
import com.app.micaihu.utils.MobclickAgentUtils
import com.app.micaihu.view.home.exclusive.adapter.ExclusiveListAdapter
import com.app.micaihu.view.user.userinfo.activity.MyHomepageDynamicActivity
import com.app.micaihu.view.utils.loadCircleImage
import com.app.micaihu.view.utils.loadImage
import com.blankj.utilcode.util.ActivityUtils
import com.chad.library.adapter.base.provider.BaseItemProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder

/**
 * 原创 大图类型
 */
class OneBigImageItemProvider : BaseItemProvider<NewsEntity>() {

    override val itemViewType: Int
        get() = ExclusiveListAdapter.itemTypeOneBigImage

    override val layoutId: Int
        get() = R.layout.exclusive_item_type_one_big_image

    override fun convert(helper: BaseViewHolder, item: NewsEntity) {
        MobclickAgentUtils.event(UmEventId.articlelist_exposed, UmEventId.original)

        helper.setText(R.id.tvAuthor, item.authorName)
        helper.setText(R.id.tvTimeAgo, item.articleTime)

        helper.setText(R.id.tvAgreeNum, item.praiseNum)
        helper.setText(R.id.tvCommentNum, item.commentNum)
        helper.setText(R.id.tvTitle, item.articleTitle)

        val articleThumb = item.articleThumb
        if (articleThumb.isNotEmpty()) {
            val ivImage = helper.getView<ImageView>(R.id.ivImg)
            ivImage.loadImage(articleThumb[0], R.mipmap.icon_default)
        }
        val ivAuthorImg = helper.getView<ImageView>(R.id.ivAuthorImg)
        ivAuthorImg.loadCircleImage(item.authorHeadPic, R.drawable.user_head_def)
        helper.getView<ImageView>(R.id.ivTag).loadImage(item.articleMark)
        val flLaudContainer = helper.getView<FrameLayout>(R.id.flLaudContainer)
        if (InteractiveUtils.getInstance().theLaudIsContains(item.articleId, true)) {
            helper.setEnabled(R.id.tvAgreeNum, false)
            flLaudContainer.tag = true
        } else {
            helper.setEnabled(R.id.tvAgreeNum, true)
            flLaudContainer.tag = item
        }
        flLaudContainer.setOnClickListener {
            if (flLaudContainer.tag == null) {
                return@setOnClickListener
            }
            InteractiveUtils.getInstance().laud((flLaudContainer), null)
        }
        ivAuthorImg.setOnClickListener {
            MyHomepageDynamicActivity.goToUserHomePage(ActivityUtils.getTopActivity(), item.authorId)
        }


    }

}